home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / ARGONET / PD / MATHS / RLAB / RLAB125.ZIP / !RLaB / toolbox / center < prev    next >
Text File  |  1994-02-21  |  854b  |  32 lines

  1. //---------------------------------------------------------------------------
  2. //
  3. // center
  4. //
  5. // Syntax: center(string,screen_width)
  6. //
  7. //  Same as printf("%s",string), but with the string centered on the screen.
  8. //
  9. //  If screen_width is given as an input argument, the string is centered
  10. //  for a screen of the given width.  Otherwise, screen_width is 80. 
  11. //
  12. // Originally written for MATLAB by Lee P. Peterson
  13. // Modified by Jeff Layton and ported to RLaB by Jeff Layton
  14. //---------------------------------------------------------------------------
  15.  
  16. center = function(string,screen_width)
  17. {
  18.    local(i,j,str1,strout,sw)
  19.  
  20.    if (!exist (screen_width)) { sw = 80; else sw = screen_width; }
  21.    i=(sw-(length(string)))/2;
  22.    str1="";
  23.  
  24.    for (j in 1:i) {
  25.         str1=str1+" ";
  26.    }
  27.    strout="";
  28.    strout=str1+string+"\n";
  29.    printf("%s",strout);
  30.  
  31. };
  32.